package com.nl.model.model;

import com.nl.model.consts.HttpStatusEnum;
import com.nl.model.model.vo.BaseVO;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

/**
 * response.
 *
 * @author: ZhaoWenXin
 * @date: 2019-04-04 14:56
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
public class ResponseVO<T> extends BaseVO {

    /**
     * 响应码
     */
    private String code;

    /**
     * 响应信息
     */
    private String message;

    /**
     * 响应的结果
     */
    private T result;


    public static ResponseVO success() {
        return ResponseVO.builder().code(HttpStatusEnum.OK.getCode()).message(HttpStatusEnum.OK.getMessage()).build();
    }

    public static ResponseVO success(Object result) {
        return ResponseVO.builder().code(HttpStatusEnum.OK.getCode()).message(HttpStatusEnum.OK.getCode()).result(result).build();
    }

    public static ResponseVO fail() {
        return ResponseVO.builder().code(HttpStatusEnum.INTERNAL_SERVICE_ERROR.getCode()).message(HttpStatusEnum.INTERNAL_SERVICE_ERROR.getMessage()).build();
    }

    public static ResponseVO fail(String code, String message) {
        return ResponseVO.builder().code(code).message(message).build();
    }

    public static ResponseVO fail(String message) {
        return ResponseVO.builder().code(HttpStatusEnum.INTERNAL_SERVICE_ERROR.getCode()).message(message).build();
    }

}
